#ifndef _FLASHTOOL_H
#define _FLASHTOOL_H

#include "F021_F28004x_C28x.h"
#include "Common.h"

// Bank0 Sector start addresses
#define Bank0_Sector0_start         0x80000
#define Bank0_Sector1_start         0x81000
#define Bank0_Sector2_start         0x82000
#define Bank0_Sector3_start         0x83000
#define Bank0_Sector4_start         0x84000
#define Bank0_Sector5_start         0x85000
#define Bank0_Sector6_start         0x86000
#define Bank0_Sector7_start         0x87000
#define Bank0_Sector8_start         0x88000
#define Bank0_Sector9_start         0x89000
#define Bank0_Sector10_start        0x8A000
#define Bank0_Sector11_start        0x8B000
#define Bank0_Sector12_start        0x8C000
#define Bank0_Sector13_start        0x8D000
#define Bank0_Sector14_start        0x8E000
#define Bank0_Sector15_start        0x8F000

// Bank1 Sector start addresses
#define Bank1_Sector0_start         0x90000
#define Bank1_Sector1_start         0x91000
#define Bank1_Sector2_start         0x92000
#define Bank1_Sector3_start         0x93000
#define Bank1_Sector4_start         0x94000
#define Bank1_Sector5_start         0x95000
#define Bank1_Sector6_start         0x96000
#define Bank1_Sector7_start         0x97000
#define Bank1_Sector8_start         0x98000
#define Bank1_Sector9_start         0x99000
#define Bank1_Sector10_start        0x9A000
#define Bank1_Sector11_start        0x9B000
#define Bank1_Sector12_start        0x9C000
#define Bank1_Sector13_start        0x9D000
#define Bank1_Sector14_start        0x9E000
#define Bank1_Sector15_start        0x9F000

//Sector length in number of 32bits
#define Sector8KB_u32length   0x800


uint16_t InitFlashAPI(void);
uint16_t EaraseSector(uint32 ulSectorAddress);
uint16_t Program4Word(uint32 ulAddress, uint16 *pBuffer);
uint16_t ReadU16DataFromFlash(uint32_t ulAddress, uint16_t *u16Data);
uint16_t ReadU32DataFromFlash(uint32_t ulAddress, uint32_t *u64Data);
uint16_t ReadU64DataFromFlash(uint32_t ulAddress, uint64_t *u64Data);
uint16_t WriteU16DataToFlash(uint32_t ulAddress, uint16_t u16Data);
uint16_t WriteU32DataToFlash(uint32_t ulAddress, uint32_t u32Data);
uint16_t WriteU64DataToFlash(uint32_t ulAddress, uint64_t u64Data);

err_state_e WriteMultiU32DataToFlash(uint32_t ulAddress, uint32_t *u32Data, uint16_t u32_len);

#endif
